

package com.hazelcast.test.starter.answer;

import org.mockito.invocation.InvocationOnMock;

import java.lang.reflect.Method;

/**
 * Default {@link org.mockito.stubbing.Answer} to create a mock for a proxied
 * {@link com.hazelcast.internal.partition.InternalPartitionService}.
 */
class PartitionServiceAnswer extends AbstractAnswer {

    PartitionServiceAnswer(Object delegate) {
        super(delegate);
    }

    @Override
    Object answer(InvocationOnMock invocation, String methodName, Object[] arguments) throws Exception {
        if (arguments.length == 1 && methodName.equals("getPartitionId")) {
            Method delegateMethod = getDelegateMethod(methodName, Object.class);
            return invoke(delegateMethod, arguments);
        } else
            if (arguments.length == 1 && methodName.equals("getPartition")) {
                return invoke(invocation, arguments);
            } else
                if (arguments.length == 0 && methodName.startsWith("get")) {
                    return invoke(invocation);
                }
        throw new UnsupportedOperationException("Method is not implemented in PartitionServiceAnswer: " + methodName);
    }
}
